package com.example.a517;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import org.litepal.LitePal;
import org.litepal.crud.ClusterQuery;
import org.litepal.crud.DataSupport;

import java.util.List;
import java.util.function.Consumer;

import entity.Book;

public class LitePalActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_lite_pal);

        Button btn_create = findViewById(R.id.create);
        btn_create.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.create) {
            //LitePal.getDatabase();
//            Book book = new Book();
//            book.setAuthor("lmt");
//            book.setName("Dan Brown");
//            book.setPages(457);
//            book.setPrice(16.87);
//            book.setPress("unKnown");
//            book.save();
//
//            Book book1 = new Book();
//            book1.setPress("known");
//            book1.setPrice(169.32);
//            book1.setName("novenber");
//            book1.setAuthor("ll");
//            book1.setPages(7890);
//            book1.save();
//            DataSupport.delete(Book.class,1);

            // DataSupport.deleteAll(Book.class,"press = ?","known");
            //List<Book> books = DataSupport.findAll(Book.class);
            List<Book> books = DataSupport.select("name","author","pages")
                    .where("pages > ?", "500").find(Book.class);
             books.forEach((book)-> Log.e("TAG", "onClick: "+book ));

        }
    }
}